package com.woniuxy.happylife.cart.controller;

import com.woniuxy.happylife.cart.service.CartService;
import com.woniuxy.happylife.entity.MallCart;
import com.woniuxy.happylife.entity.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title: CartController
 * @ProjectName: happy-life
 * @Description: TODO
 * @Author: chowinggum
 * @Date: 2022/2/17 17:36
 */
@RequestMapping("/cart")
@RestController
public class CartController {
    @Autowired
    CartService cartService;

    @GetMapping("/findAllCartByUid/{uid}")
    public ResponseEntity findAllCart(@PathVariable("uid") int uid){
        List<MallCart> allCart = cartService.findAllCartByUid(uid);
        return new ResponseEntity(200,"查询成功",allCart);

    }

    @PostMapping("/addCart")
    public ResponseEntity addCart(@RequestBody MallCart cart){
        int i = cartService.addCart(cart);
        if(i>0){
            return new ResponseEntity(200,"添加成功",null);
        }else {
            return new ResponseEntity(401,"添加失败",null);
        }

    }

    @DeleteMapping("/deleteCart/{cartid}")
    public ResponseEntity deleteCart(@PathVariable("cartid") int cartid){
        int i = cartService.deleteCart(cartid);
        if(i>0){
            return new ResponseEntity(200,"删除成功",null);
        }else {
            return new ResponseEntity(401,"删除失败",null);
        }
    }
}
